<?php
/**
 * User: aka
 * Time: 1:03
 */

namespace app\write\controller;

use app\validate\riven\SendRiven;
use think\facade\Session;
use think\Request;

class Riven
{
    private $userId;

    public function __construct()
    {
        $this->userId = Session::get('user_info.id');
    }

    public function __destruct()
    {
        unset(
            $this->userId
        );
    }

    public function sendRiven(Request $request)
    {
        $validate = new SendRiven();
        if (!$validate->check($request->param())) {
            return json($validate->getError());
        }else{
            \app\tenno\model\Riven::create([
                'stuff_name' => $request->param('stuff_name'),
                'unit_price' => $request->param('unit_price'),
                'num' => $request->param('num'),
                'rank' => $request->param('rank'),
                'entry_1' => $request->param('entry_1'),
                'entry_2' => $request->param('entry_2'),
                'entry_3' => $request->param('entry_3'),
                'entry_4' => $request->param('entry_4'),
                'uid' => $this->userId
            ]);
            return json(['state' => 200]);
        }
    }
}